#!/usr/bin/env python3
"""
添加任务机器人关联表的迁移脚本
"""

import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app import app, db
from models import TaskRobotAssociation

def create_task_robot_association_table():
    """创建任务机器人关联表"""
    try:
        with app.app_context():
            # 创建任务机器人关联表
            db.create_all()
            
            # 检查表是否创建成功
            inspector = db.inspect(db.engine)
            if 'task_robot_association' in inspector.get_table_names():
                print("✅ 任务机器人关联表创建成功！")
                print("   - task_robot_association (任务机器人关联表)")
                
                # 显示表结构
                columns = inspector.get_columns('task_robot_association')
                print("   表结构:")
                for column in columns:
                    print(f"     - {column['name']}: {column['type']}")
            else:
                print("❌ 任务机器人关联表创建失败！")
                
    except Exception as e:
        print(f"❌ 创建任务机器人关联表时出错: {str(e)}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    print("开始创建任务机器人关联表...")
    create_task_robot_association_table()
    print("迁移完成！") 